#import "sprite_game_arrow_preline.h"

@implementation SpriteGameArrowPreline

@synthesize active = active_;
@synthesize basePoint = basePoint_;

- (id)initSpriteGameArrowPreLine
{
	if ((self = [super init]))
	{
		/*OpenGL*/
		for (int i = 0; i < VERTEX_COUNT; ++i)
		{
			indexArray_[i] = i;
		}
		memset(&vertexArray_, 0, sizeof vertexArray_);
		memset(&parabolaData_, 0, sizeof(TMVParabolaData));
		active_ = false;
	}
	return self;
}

- (void)draw
{
	if (active_)
	{
		glDisable(GL_TEXTURE_2D);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_COLOR_ARRAY);

		glVertexPointer(2, GL_FLOAT, 0, vertexArray_);
		glPointSize(4.0f);
		glColor4f(color_.r, color_.g, color_.b, 1.0);
		glDrawElements(GL_POINTS, VERTEX_COUNT, GL_UNSIGNED_BYTE, indexArray_);

		glEnable(GL_TEXTURE_2D);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);
	}
}

- (void)SetParabolaData:(CGPoint)StartSpeed
{
	float _TimeStep;
	CGPoint _Point;

	memset(&parabolaData_, 0, sizeof(TMVParabolaData));
	parabolaData_.start_speed = StartSpeed;
	tmvComputeParabola(&parabolaData_);

	_TimeStep = parabolaData_.time / VERTEX_COUNT;
	for (int i = 0; i < VERTEX_COUNT; ++i)
	{
		tmvComputeParabolaPoint(&parabolaData_, _TimeStep * i, &_Point);
		vertexArray_[2 * i] = _Point.x * g_ParabolaScaleRatio;
		vertexArray_[2 * i + 1] = _Point.y * g_ParabolaScaleRatio;
	}
}

@end